import pygame
from pygame.sprite import Sprite

import global_var


class StartScreen(Sprite):

    def __init__(self, screen, settings):
        super().__init__()
        self.screen = screen
        self.screen_rect = screen.get_rect()
        # 背景
        self.image = pygame.image.load(settings.image_paths['start_screen_image']).convert_alpha()
        self.image.fill(settings.colors['bg_color'])  # 填充背景颜色为了防止图片加载失败
        # 游戏标题
        self.title_font = pygame.font.SysFont('Ink Free', 50, bold=True)  # title_font 是一个字体对象，用于渲染文本
        self.title = self.title_font.render('Alien Invasion', True, settings.colors['title_color'])
        self.title_rect = self.title.get_rect()
        self.title_rect.centerx = self.screen_rect.centerx
        self.title_rect.top = 150
        # 提示文字
        self.prompt_font = pygame.font.SysFont('Ink Free', 25, bold=True)
        self.prompt = self.prompt_font.render('Press Enter to start', True, settings.colors['prompt_color'])
        self.prompt_rect = self.prompt.get_rect()
        self.prompt_rect.centerx = self.screen_rect.centerx
        self.prompt_rect.top = 300
        # 关于按钮
        self.about_font = pygame.font.SysFont('Ink Free', 25, bold=True)
        self.about = self.about_font.render('About', True, settings.colors['about_color'])
        self.about_rect = self.about.get_rect()
        self.about_rect.topright = (780, 20)

    def draw(self):
        """绘制开始屏幕"""
        self.screen.blit(self.image, (0, 0))
        self.screen.blit(self.title, self.title_rect)
        self.screen.blit(self.prompt, self.prompt_rect)
        self.screen.blit(self.about, self.about_rect)

    def check_about_click(self, mouse_pos):
        """检查是否点击了关于文字"""
        if self.about_rect.collidepoint(mouse_pos):
            global_var.set_value('show_about_screen', True)